< previous page page_555 next page >

Page 555
what its name is, which DLL it resides in, what parameters it expects, and what return type, if any, it returns. You accomplish this using the Declare statement. The following is an example of how you might declare a couple of API calls to Visual Basic:
9f31265bb40b592b1929e18a47ab28e5.gif
Declare Function GetWinFlags Lib "Kernel" () As Long
Declare Sub UpdateWindow Lib "User" (ByVal hWnd As Integer)
The declaration of a Sub is used for those routines that do not return a value. The declaration of a Function is used for those API calls that do return a value. There are only a few API calls that do not return a value, so youll declare most of them as functions.
Declarations of API calls can be either Public or Private when declared in the General Declarations section of a BAS module. You may also declare API calls in a class module or form module, but the declarations in these files must be Private.
API Text Viewer Utility
You dont need to look up the declarations of API calls and type all the declarations in yourselfinstead, you can use a utility thats supplied with Visual Basic. Under the Add-ins, Add-In Manager, youll find the utility called VB6 API Viewer, which you can load into the Add-Ins menu. When you select the API Text Viewer utility, youll see a screen similar to the one shown in Figure 28.1. To load in the declarations, you must select File, Load Text File from the API Text Viewer menu. Choose the Win32api.txt file from the list of files presented. If youre prompted to convert the file to a database, go ahead and choose that optionthis will speed up the loading of the declarations substantially.
Now that you have the API Text Viewer and the declarations loaded, you can find the declaration you want, double-click it, and have it placed in the text box on the bottom of the screen. Once you have one or more declarations loaded into the text box, click the Copy button to copy all the declarations into the Clipboard. Once there, you can switch to your Visual Basic program and paste the declarations into a BAS module.

 
< previous page page_555 next page >

If you like this book, buy it!